﻿using ColladaDotNet;
using System;
using System.Collections.ObjectModel;

namespace contentviewer.ViewModel
{
    public class ColladaNodeViewModel : NodeViewModel
    {
		readonly COLLADA _node;
		private ObservableCollection<NodeViewModel> _selectedItems;

        public ColladaNodeViewModel(ColladaXmlNode node, NodeViewModel root, NodeViewModel parent)
            :   base(root, parent)
        {
            _node = node as COLLADA;
			_selectedItems = new ObservableCollection<NodeViewModel>();
        }

        public string Content
        {
			get
			{
				var _collada = _node as COLLADA;
				switch (_collada.version)
				{
					case VersionType.Item140: return "COLLADA v1.4.0";
					case VersionType.Item141: return "COLLADA v1.4.1";
					case VersionType.Item150: return "COLLADA v1.5.0";
				}
				return "";
			}
		}

		protected override void LoadChildren()
		{
			base.LoadChildren();
			var collada = _node;
			base.Children.Add(new AssetViewModel(this, this, collada.asset));
			if (collada.library_materials != null)
				base.Children.Add(new LibMaterialViewModel(this, this, collada.library_materials));
			if (collada.library_geometries != null)
				base.Children.Add(new LibGeometryViewModel(this, this, collada.library_geometries));
			if (collada.library_visual_scenes != null)
				base.Children.Add(new LibVisualSceneViewModel(this, this, collada.library_visual_scenes));
		}

		public override bool IsSelected
		{
			get
			{
				return base.IsSelected;
			}
			set
			{
				if (value == true)
					(Root as ColladaNodeViewModel).SelectedItems.Add(this);
				else
					(Root as ColladaNodeViewModel).SelectedItems.Remove(this);
				base.IsSelected = value;
			}
		}

		public ObservableCollection<NodeViewModel> SelectedItems
		{
			get { return _selectedItems; }
		}

		public override string ToString()
		{
			return this.Content;
		}
    }
}
